package com.ruoyi.project.mahjong.controller;

import java.util.List;

import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.redis.RedisCache;
import com.ruoyi.project.system.domain.SysUser;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.mahjong.domain.TRoom;
import com.ruoyi.project.mahjong.service.ITRoomService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 房间Controller
 *
 * @author ruoyi
 * @date 2023-10-07
 */
@RestController
@RequestMapping("/mahjong/room")
public class TRoomController extends BaseController
{
    @Autowired
    private ITRoomService tRoomService;
    @Autowired
    private RedisCache redisCache;
    /**
     * 查询房间列表
     */
    @PreAuthorize("@ss.hasPermi('mahjong:room:list')")
    @GetMapping("/list")
    public TableDataInfo list(TRoom tRoom)
    {
        startPage();
        List<TRoom> list = tRoomService.selectTRoomList(tRoom);
        return getDataTable(list);
    }
    @GetMapping("/frontlist")
    public AjaxResult frontlist(TRoom tRoom)
    {
        SysUser user = SecurityUtils.getLoginUser().getUser();
        Long shopId = redisCache.getCacheObject(Constants.SHOP_SUF + user.getUserId());
        tRoom.setBak1(shopId.toString());
        List<TRoom> list = tRoomService.selectTRoomList(tRoom);
        TRoom room=new TRoom();
        room.setRoomName("全部");
        list.add(0,room);
        return AjaxResult.success(list);
    }
    /**
     * 导出房间列表
     */
    @PreAuthorize("@ss.hasPermi('mahjong:room:export')")
    @Log(title = "房间", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TRoom tRoom)
    {
        List<TRoom> list = tRoomService.selectTRoomList(tRoom);
        ExcelUtil<TRoom> util = new ExcelUtil<TRoom>(TRoom.class);
        return util.exportExcel(list, "room");
    }

    /**
     * 获取房间详细信息
     */
    @PreAuthorize("@ss.hasPermi('mahjong:room:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tRoomService.selectTRoomById(id));
    }

    /**
     * 新增房间
     */
    @PreAuthorize("@ss.hasPermi('mahjong:room:add')")
    @Log(title = "房间", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TRoom tRoom)
    {
        return toAjax(tRoomService.insertTRoom(tRoom));
    }

    /**
     * 修改房间
     */
    @PreAuthorize("@ss.hasPermi('mahjong:room:edit')")
    @Log(title = "房间", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TRoom tRoom)
    {
        return toAjax(tRoomService.updateTRoom(tRoom));
    }

    /**
     * 删除房间
     */
    @PreAuthorize("@ss.hasPermi('mahjong:room:remove')")
    @Log(title = "房间", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tRoomService.deleteTRoomByIds(ids));
    }
}
